home *** CD-ROM | disk | FTP | other *** search
/ An Introduction to Progr…l Basic 6.0 (4th Edition) / An Introduction to Programming using Visual Basic 6.0.iso / PROGRAMS / CH10 / 10-3-2.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-09-18  |  4.4 KB  |  128 lines

  1. VERSION 5.00
  2. Begin VB.Form frm10_3_2 
  3.    Caption         =   "Clustered Bar Chart"
  4.    ClientHeight    =   4665
  5.    ClientLeft      =   1410
  6.    ClientTop       =   1800
  7.    ClientWidth     =   6360
  8.    BeginProperty Font 
  9.       Name            =   "MS Sans Serif"
  10.       Size            =   8.25
  11.       Charset         =   0
  12.       Weight          =   700
  13.       Underline       =   0   'False
  14.       Italic          =   0   'False
  15.       Strikethrough   =   0   'False
  16.    EndProperty
  17.    LinkTopic       =   "Form1"
  18.    PaletteMode     =   1  'UseZOrder
  19.    ScaleHeight     =   4665
  20.    ScaleWidth      =   6360
  21.    Begin VB.PictureBox picEnroll 
  22.       Height          =   3735
  23.       Left            =   240
  24.       ScaleHeight     =   3675
  25.       ScaleWidth      =   5835
  26.       TabIndex        =   1
  27.       Top             =   720
  28.       Width           =   5895
  29.    End
  30.    Begin VB.CommandButton cmdDraw 
  31.       Caption         =   "Draw Chart of Two-Year College Enrollments"
  32.       Height          =   495
  33.       Left            =   960
  34.       TabIndex        =   0
  35.       Top             =   120
  36.       Width           =   4215
  37.    End
  38. Attribute VB_Name = "frm10_3_2"
  39. Attribute VB_GlobalNameSpace = False
  40. Attribute VB_Creatable = False
  41. Attribute VB_PredeclaredId = True
  42. Attribute VB_Exposed = False
  43. Private Sub cmdDraw_Click()
  44.   Dim numYears As Integer, maxEnroll As Single
  45.   'Bar Chart of Total Two-Year College Enrollments
  46.   numYears = 5
  47.   ReDim label(1 To numYears) As String
  48.   ReDim male(1 To numYears) As Single
  49.   ReDim female(1 To numYears) As Single
  50.   Call ReadData(label(), male(), female(), numYears, maxEnroll)
  51.   Call DrawAxes(numYears, maxEnroll)
  52.   Call DrawData(male(), female(), numYears)
  53.   Call ShowTitle(maxEnroll)
  54.   Call ShowLabels(label(), numYears, maxEnroll)
  55.   Call ShowLegend(maxEnroll)
  56. End Sub
  57. Private Sub DrawAxes(numYears As Integer, maxEnroll As Single)
  58.   'Draw axes
  59.   picEnroll.Scale (-1, 1.2 * maxEnroll)-(numYears + 1, -0.2 * maxEnroll)
  60.   picEnroll.Line (-1, 0)-(numYears + 1, 0)
  61.   picEnroll.Line (0, -0.1 * maxEnroll)-(0, 1.1 * maxEnroll)
  62. End Sub
  63. Private Sub DrawData(male() As Single, female() As Single, numYears As Integer)
  64.   'Draw rectangles
  65.   For i = 1 To numYears
  66.     picEnroll.Line (i - 0.3, male(i))-(i, 0), , BF
  67.     picEnroll.Line (i, female(i))-(i + 0.3, 0), , B
  68.   Next i
  69. End Sub
  70. Private Sub Locate(x As Single, y As Single)
  71.   picEnroll.CurrentX = x
  72.   picEnroll.CurrentY = y
  73. End Sub
  74. Private Sub ReadData(label() As String, male() As Single, female() As Single, numYears As Integer, maxEnroll As Single)
  75.   Dim i As Integer
  76.   'Assume the data has been placed in the file ENROLLMF.DAT
  77.   '(First line is file is "1960", 283, 170)
  78.   'Read data into arrays, find highest enrollment
  79.   Open App.Path & "\ENROLLMF.TXT" For Input As #1
  80.   maxEnroll = 0
  81.   For i = 1 To numYears
  82.     Input #1, label(i), male(i), female(i)
  83.     If male(i) > maxEnroll Then
  84.         maxEnroll = male(i)
  85.     End If
  86.     If female(i) > maxEnroll Then
  87.         maxEnroll = female(i)
  88.     End If
  89.   Next i
  90.   Close #1
  91. End Sub
  92. Private Sub ShowLabels(label() As String, numYears As Integer, maxEnroll As Single)
  93.   Dim i As Integer, lbl As String, lblWid As Single
  94.   Dim lblHght As Single, tickFactor As Single
  95.   'Draw tick marks and label them
  96.   For i = 1 To numYears
  97.     lbl = label(i)
  98.     lblWid = picEnroll.TextWidth(lbl)
  99.     tickFactor = 0.02 * maxEnroll
  100.     picEnroll.Line (i, -tickFactor)-(i, tickFactor)
  101.     Call Locate(i - lblWid / 2, -tickFactor)
  102.     picEnroll.Print lbl
  103.   Next i
  104.   lbl = Str(maxEnroll)
  105.   lblWid = picEnroll.TextWidth(lbl)
  106.   lblHght = picEnroll.TextHeight(lbl)
  107.   tickFactor = 0.01 * numYears
  108.   picEnroll.Line (-tickFactor, maxEnroll)-(tickFactor, maxEnroll)
  109.   Call Locate(-tickFactor - lblWid, maxEnroll - lblHght / 2)
  110.   picEnroll.Print lbl
  111. End Sub
  112. Private Sub ShowLegend(maxEnroll As Single)
  113.   'Show legend
  114.   picEnroll.Line (0.1, 1.05 * maxEnroll)-(0.9, 0.95 * maxEnroll), , BF
  115.   Call Locate(1, 1.05 * maxEnroll)
  116.   picEnroll.Print "Male"
  117.   picEnroll.Line (0.1, 0.9 * maxEnroll)-(0.9, 0.8 * maxEnroll), , B
  118.   Call Locate(1, 0.9 * maxEnroll)
  119.   picEnroll.Print "Female"
  120. End Sub
  121. Private Sub ShowTitle(maxEnroll As Single)
  122.   'Display source and title
  123.   Call Locate(-0.5, -0.1 * maxEnroll)
  124.   picEnroll.Print "Source: Statistical Abstract of the United States"
  125.   Call Locate(0.5, 1.2 * maxEnroll)
  126.   picEnroll.Print "Two-Year College Enrollments (in thousands)"
  127. End Sub
  128.